package com.lagou.homewok.mr;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.LongWritable;
import org.apache.hadoop.io.NullWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class SortDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {

        //1.获取配置文件对象，获取job实例
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf, "SortDriver");

        //2.设置指定jar
        job.setJarByClass(SortDriver.class);

        //3.指定mapper/reducer类
        job.setMapperClass(SortMapper.class);
        job.setReducerClass(SortReducer.class);

        //4.指定Mapper输出的kv类型
        job.setMapOutputKeyClass(LongWritable.class);
        job.setMapOutputValueClass(NullWritable.class);

        //5.指定结果输出的kv类型
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(NullWritable.class);

        //6.指定输入输出路径
        FileInputFormat.setInputPaths(job, new Path("/Users/yefan/Sites/java/data/file"));
        FileOutputFormat.setOutputPath(job, new Path("/Users/yefan/Sites/java/data/file/out"));

        //7.提交作业
        boolean b = job.waitForCompletion(true);

        //退出，0正常退出，1非正常退出
        System.exit(b ? 0 : 1);
    }
}
